#!/bin/sh
# Config Manager init script.
. /etc/utils.sh

APP="configmanager"
BINARY="/app/spacecast/configmanager"
FLAGS="-logtostderr"

# Make sure we have a directory to store configs for SpaceCast.
mkdir -p /config/spacecast

running() {
  [ -n "$(pgrep -f "$BINARY")" ]
}

case "$1" in
  start)
    if running; then
      echo "Config Manager is already running!"
    else
      babysit_start 10 "$APP" "$BINARY" "$FLAGS"
    fi
    ;;
  stop)
    pkill -f "$BINARY"
    ;;
  restart|reload)
    $0 stop;$0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac
